﻿/**
 * Created by Administrator on 2017/8/21.
 */
define(['api'],function (api) {
    var LookedHouseList = {
        name: 'looked-house-list',
        template: ''
        + '<div class="see-record">'
        + '    <div class="see-record-box">'
        + '        <div class="see-record-center">'
        + '            <i-table :columns="lookedHouseListHead" :data="lookedHouseList"  ref="table"></i-table>'
        + '        </div>'
        + '    </div>'
        + '</div>',
        props: {
        },
        data: function () {
            return {
                customerId: '',
                lookedHouseListHead: [
                    {
                        title: '带看时间',
                        key: 'VisitTime',
                        width: '16.14%'
                    },
                    {
                        title: '带看房源',
                        key: 'CustomerName',
                        width: '20.5%'
                    },
                    {
                        title: '带看人',
                        key: 'VisitorName',
                        width: '15.14%'
                    },
                    {
                        title: '购买意向',
                        key: 'PurchasingIntentionText',
                        width: '17.35%'
                    },
                    //{
                    //    title: '带看详情',
                    //    key: 'Remark',
                    //}
                    {
                        title: '带看详情',
                        key: 'operation',
                        render: (function (params) {
                            return (
                                ' <Tooltip placement="top" content="查看"><p class="eyes p-click" type="primary" v-on:click="operation(lookedHouseList[' + params._index + '].Id)"></p></Tooltip>'
                            )
                        })
                    }
                ],
                lookedHouseList: [
                    {
                        seeTime: '2017.02.02',
                        seeCustomer: '客户1',
                        seePeople: '销售员A',
                        purchaseIntention: '意向强烈',
                        seeDetails: '123123',
                        cellClassName: {
                            purchaseIntention: 'yxql',
                        }
                    },
                    {
                        seeTime: '2017.02.02',
                        seeCustomer: '客户1',
                        seePeople: '销售员A',
                        purchaseIntention: '意向强烈',
                        seeDetails: '123123',
                        cellClassName: {
                            purchaseIntention: 'yxql',
                        }
                    },
                ],
            }
        },
        mounted: function () {
            var thisLooked = this;
            //监听getCustomerDetail
            window.bus.$on("getCustomerDetail", function (Id) {
                thisLooked.customerId = Id;
                thisLooked.getLookedHouseList(Id);
            });
            //监视submitVisitRecordSuccess
            window.bus.$on("submitVisitRecordSuccess", function () {
                thisLooked.getLookedHouseList(thisLooked.customerId);
            });
        },
        methods: {
            getLookedHouseList: function (Id) {
                var thisLooked = this;
                api.Get_Visit_Record_Of_Looked_House({customerId: Id})
                    .done(function (data) {
                        if (data.IsSuccess) {
                            thisLooked.lookedHouseList = thisLooked.setCellClassName(data.ResultObject);
                        } else {
                            thisLooked.$Message.error(data.ErrMsg);
                        }
                    })
                    .fail(function () {
                        thisLooked.$Message.error('查询出错');
                    });
            },
            setCellClassName: function (data) {
                for (var i = 0; i < data.length; i++) {
                    data[i].cellClassName = {};
                    data[i].cellClassName.PurchasingIntentionText = 'yxql' + (data[i].PurchasingIntention + 1);
                }
                return data;
            },
            operation: function (Id) {
                //触发TradedOperation
                window.bus.$emit("TradedOperation", Id);
            }
        },
    };
    return LookedHouseList;
});

